$("#joinClass").on("click",function(){
        window.open ("search_teacher.html", "_blank", "height=700, width=1100, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
})

function createJoinedTab(data){ console.log(data)
	var tab=document.getElementById("studentTab");
	for (var i=0;i<data.length;i++){
		var tr=document.createElement("tr");

		var td=document.createElement("td");
		td.textContent=data[i].class_number;
		tr.appendChild(td)		

		var td=document.createElement("td");
		td.textContent=data[i].class_name;
		tr.appendChild(td)		

		var td=document.createElement("td");
		td.textContent=data[i].teacher_chinesename;
		tr.appendChild(td)		

		var td=document.createElement("td");
		var button=document.createElement("button")
		button.className="btn btn-xs btn-success"
		button.textContent="已加入"
		td.appendChild(button)
		tr.appendChild(td)
		
		var td=document.createElement("td");
		var test=document.createElement("a")
		var fatherPage=window.location.href.split("/")
		fatherPage=fatherPage[fatherPage.length-1]
		var location=fatherPage+"?page=student_test.html&id=" + data[i].class_number +"&data="+JSON.stringify(data[i])
		test.setAttribute("href",location)
		test.className="btn btn-xs btn-success"
		test.textContent="实验作业"
		td.appendChild(test)

		var btn=document.createElement("a")
		var location="student_index.html?page=student_xitilist.html&id=" + data[i].class_number +"&data="+JSON.stringify(data[i])
		btn.setAttribute("href",location)
		btn.className="btn btn-primary btn-xs"
		btn.textContent="习题作业"
		btn.style.cssText="margin-left:5px;"
		td.appendChild(btn)
		tr.appendChild(td)
		
		var btn=document.createElement("button")
		btn.setAttribute("class_number",data[i].class_number)
		btn.className="btn btn-warning btn-xs"
		btn.textContent="退出班级"
		btn.style.cssText="margin-left:5px;"
		btn.onclick=function(){
			var classNumber=this.getAttribute("class_number")
			if(confirm("真的要退出吗？")===false){
				return false;
			}
			$.ajax({
				"url":"/exit_class/",
				"error":errorAjax,
				"data":{"sid":classNumber},
				"beforeSend":start_load_pic,
				"complete":stop_load_pic,
				"dataType":"jsonp",
				"success":function(data){
					if(!data.status){
						showErrorInfo(data.content)
						return false;
					}
					alert("已退出！")
					window.location.reload()
				}
			})
		}
		td.appendChild(btn)
		td.appendChild(btn)
		
		tab.appendChild(tr)
	}
}


$(function(){
	jQuery.ajax({
		"url":"/get_joined_class/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"success":function(data){
			if(!data.status){
				showErrorInfo(data.content);
				return false;
			}
			else{
				createJoinedTab(data.content);
			}
		}
	})
})
